package com.cube.dp.base.error;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import org.apache.commons.lang3.ArrayUtils;

/**
 * @author cube.li
 * @date 2021/12/5 16:17
 */
@Getter
public class CommonBuException extends RuntimeException {

    private final int code;

    private final String msg;

    public CommonBuException(ApiResultCode apiResultCode) {
        this.code = apiResultCode.getCode();
        this.msg = apiResultCode.getMsg();
    }

    public CommonBuException(ApiResultCode apiResultCode, Object... params) {
        this.code = apiResultCode.getCode();
        if (ArrayUtils.isNotEmpty(params)) {
            this.msg = StrUtil.format(apiResultCode.getMsg(), params);
        } else {
            this.msg = apiResultCode.getMsg();
        }
    }

    @Override
    public String getMessage() {
        return this.msg;
    }
}
